/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.EntrySearchFilter;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.SearchDirectoryOptions;
/*     */ import com.zimbra.cs.account.SearchDirectoryOptions.ObjectType;
/*     */ import com.zimbra.cs.account.SearchDirectoryOptions.SortOpt;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.ldap.LdapEntrySearchFilter;
/*     */ import com.zimbra.cs.gal.GalExtraSearchFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId;
/*     */ import com.zimbra.cs.session.AdminSession;
/*     */ import com.zimbra.cs.session.Session.Type;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SearchCalendarResources
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public static final String BY_NAME = "name";
/*     */   public static final String BY_ID = "id";
/*     */   
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  57 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  63 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  64 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  66 */     int limit = (int)request.getAttributeLong("limit", 2147483647L);
/*     */     
/*  68 */     if (limit == 0) limit = Integer.MAX_VALUE;
/*  69 */     int offset = (int)request.getAttributeLong("offset", 0L);
/*  70 */     String domain = request.getAttribute("domain", null);
/*  71 */     boolean applyCos = request.getAttributeBool("applyCos", true);
/*  72 */     String sortBy = request.getAttribute("sortBy", null);
/*  73 */     boolean sortAscending = request.getAttributeBool("sortAscending", true);
/*  74 */     String attrsStr = request.getAttribute("attrs", null);
/*  75 */     String[] attrs = attrsStr == null ? null : attrsStr.split(",");
/*     */     
/*  77 */     EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  82 */     if (isDomainAdminOnly(zsc)) {
/*  83 */       if (domain == null) {
/*  84 */         domain = getAuthTokenAccountDomain(zsc).getName();
/*     */       } else {
/*  86 */         checkDomainRight(zsc, domain, AdminRight.PR_ALWAYS_ALLOW);
/*     */       }
/*     */     }
/*     */     
/*  90 */     Domain d = null;
/*  91 */     if (domain != null) {
/*  92 */       d = prov.get(Key.DomainBy.name, domain);
/*  93 */       if (d == null) {
/*  94 */         throw AccountServiceException.NO_SUCH_DOMAIN(domain);
/*     */       }
/*     */     }
/*  97 */     AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
/*  98 */     AdminAccessControl.SearchDirectoryRightChecker rightChecker = new AdminAccessControl.SearchDirectoryRightChecker(aac, prov, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 103 */     String query = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter);
/*     */     
/* 105 */     SearchDirectoryOptions options = new SearchDirectoryOptions();
/* 106 */     options.setDomain(d);
/* 107 */     options.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.resources });
/* 108 */     options.setFilterString(ZLdapFilterFactory.FilterId.ADMIN_SEARCH, query);
/* 109 */     options.setReturnAttrs(attrs);
/* 110 */     options.setSortOpt(sortAscending ? SearchDirectoryOptions.SortOpt.SORT_ASCENDING : SearchDirectoryOptions.SortOpt.SORT_DESCENDING);
/* 111 */     options.setSortAttr(sortBy);
/* 112 */     options.setConvertIDNToAscii(true);
/*     */     
/*     */ 
/* 115 */     int limitMax = offset + limit;
/* 116 */     AdminSession session = (AdminSession)getSession(zsc, Session.Type.ADMIN);
/* 117 */     List<NamedEntry> resources; List<NamedEntry> resources; if (session != null) {
/* 118 */       resources = session.searchDirectory(options, offset, rightChecker);
/*     */     } else {
/* 120 */       resources = prov.searchDirectory(options);
/* 121 */       resources = rightChecker.getAllowed(resources, limitMax);
/*     */     }
/*     */     
/* 124 */     Element response = zsc.createElement(AdminConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
/*     */     
/* 126 */     for (int numEntries = offset; (numEntries < limitMax) && (numEntries < resources.size()); numEntries++) {
/* 127 */       NamedEntry entry = (NamedEntry)resources.get(numEntries);
/* 128 */       ToXML.encodeCalendarResource(response, (CalendarResource)entry, applyCos, null, aac.getAttrRightChecker(entry));
/*     */     }
/*     */     
/*     */ 
/* 132 */     response.addAttribute("more", numEntries < resources.size());
/* 133 */     response.addAttribute("searchTotal", resources.size());
/* 134 */     return response;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 139 */     relatedRights.add(Rights.Admin.R_getCalendarResource);
/* 140 */     relatedRights.add(Rights.Admin.R_listCalendarResource);
/*     */     
/* 142 */     notes.add("If the authenticated admin does not have the corresponding list{Entry} right for an entry, the entry is skipped in the getAllXXX/searchXXX/searchDirectoryResponse,  no PERM_DENIED exception will be thrown. Attributes that are not allowed to be get by the authenticated admin will be returned as <a n=\"{attr-name}\" pd=\"1\"/>.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/SearchCalendarResources.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */